1
Evolution of LLM Architectures: From BERT to GPT and T5
AI012 Lesson 2
00:00

The Triad of Transformer Architectures

The evolution of Large Language Models is marked by a Paradigm Shift: transitioning from task-specific models to "Unified Pre-training" where a single architecture adapts to multiple NLP needs.

At the core of this shift is the Self-Attention mechanism, which allows models to weigh the importance of different words in a sequence:

$$Attention(Q, K, V) = softmax\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$

1. Encoder-Only (BERT)

  • Mechanism: Masked Language Modeling (MLM).
  • Behavior: Bidirectional context; the model "sees" the entire sentence at once to predict hidden words.
  • Best For: Natural Language Understanding (NLU), sentiment analysis, and Named Entity Recognition (NER).

2. Decoder-Only (GPT)

  • Mechanism: Auto-regressive Modeling.
  • Behavior: Left-to-right processing; predicts the next token based strictly on preceding context (causal masking).
  • Best For: Natural Language Generation (NLG) and creative writing. This is the foundation of modern LLMs like GPT-4 and Llama 3.

3. Encoder-Decoder (T5)

  • Mechanism: Text-to-Text Transfer Transformer.
  • Behavior: An encoder processes the input string into a dense representation, and a decoder generates the target string.
  • Best For: Translation, summarization, and parity tasks.
Key Insight: The Decoder Dominance
The industry has largely consolidated around Decoder-only architectures due to their superior scaling laws and emergent reasoning abilities in zero-shot scenarios.
VRAM Context Window Impact
In Decoder-only models, the KV Cache grows linearly with sequence length. A 100k context window requires significantly more VRAM than an 8k window, making local deployment of long-context models challenging without quantization.
arch_comparison.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why did the industry move from BERT-style encoders to GPT-style decoders for Large Language Models?
Decoders scale more effectively for generative tasks and follow-up instructions via next-token prediction.
Encoders cannot process text bidirectionally.
Decoders require less training data for classification tasks.
Encoders are incompatible with the Self-Attention mechanism.
Question 2
Which architecture treats every NLP task as a "text-to-text" problem?
Encoder-Only (BERT)
Decoder-Only (GPT)
Encoder-Decoder (T5)
Recurrent Neural Networks (RNN)
Challenge: Architectural Bottlenecks
Analyze deployment constraints based on architecture.
If you are building a model for real-time document summarization where the input is very long, explain why a Decoder-only model might be preferred over an Encoder-Decoder model in modern deployments.
Step 1
Identify the architectural bottleneck regarding context processing.
Solution:
Encoder-Decoders must process the entire long input through the encoder, then perform cross-attention in the decoder, which can be computationally heavy and complex to optimize for extremely long sequences. Decoder-only models process everything uniformly. With modern techniques like FlashAttention and KV Cache optimization, scaling the context window in a Decoder-only model is more streamlined and efficient for real-time generation.
Step 2
Justify the preference using Scaling Laws.
Solution:
Decoder-only models have demonstrated highly predictable performance improvements (Scaling Laws) when increasing parameters and training data. This massive scale unlocks "emergent abilities," allowing a single Decoder-only model to perform zero-shot summarization highly effectively without needing the task-specific fine-tuning often required by smaller Encoder-Decoder setups.